package FilePanel.controls;

import java.util.Collections;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import FilePanel.Control;
import FilePanel.FilePanelControl;
import FilePanel.FilePanelModel;

/**
 * @author      Erwan Osouf, Lucas Ennouchi
 * @version     1.0                                
 * @since       29/01/2012
 */

public class ControlList extends Control implements ListSelectionListener,Observer{
	
	private JList list;
	
	/**
	 * Constructor 
	 * @param list
	 */
	public ControlList(JList list) {
		super();
		this.list = list;
	}

	/**
	 * @param e the listselectionevent
	 */
	@Override
	public void valueChanged(ListSelectionEvent e) {
		getSuperController().setSelectedIndex(list.getSelectedIndices());
	}

	/**
	 * updates the filePanelModel
	 * 
	 */
	@Override
	public void update(Observable arg0, Object arg1) {
		FilePanelModel model = (FilePanelModel)arg0;
		list.setListData(model.getFiles().toArray());
	}
	
}
